<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统</title>
</head>
<body>
<div id="currentHost"></div>
<div style="align-content: center">当前登录用户：<span id="loginStatus"></span></div>
<div>
    <button onclick="test()">测试接口访问</button>
    <button onclick="clearToken()">注销登录</button>
</div>
<script src="jquery-1.8.0.min.js"></script>
<script src="loadwith.js"></script>
<script src="https://cdn.bootcss.com/Base64/1.0.2/base64.min.js"></script>
<script>
    test();
    if (localStorage.getItem("token")!=null){
        clientreq('get',"/getUser",null,getUser);
        $('#currentHost').text("当前ip，端口：" + location.origin);
    }
    function getUser(res) {
        $('#loginStatus').text(res.data.name);
    }
    //测试token是否有效
    function test() {
        clientreq('get',"/test",null,testTemp);
    }
    function testTemp(res) {
        if (res.code =='10006') {
        } else {
            goToLoginServer();
        }
    }
    //注销登录
    function clearToken() {
        clientreq('get',"/logout",null,clear);
    }
    function clear(data) {
        localStorage.removeItem("token");
        goToLoginServer();
    }

    function goToLoginServer() {
        alert("当前无登录信息，跳转到认证中心");
        localStorage.setItem("redirect", location.href);
        location.href = encodeURI("http://localhost:8888/sso/static/index.html?order=checkLogin&redirect=" + window.location.origin + "/static/redirect.html");
    }

</script>
</body>
</html>